package org.computate.model.item;

import org.apache.commons.lang3.StringUtils;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Subclass;

@Cached
@Subclass
public class Review extends Model {
	
	public String getModelDisplayName() { return "Review"; }
	public String getModelPluralName() { return "Reviews"; }
	public String getAddLink() { return "/page/form/ReviewForm/ReviewForm.jsp"; }
	public String getAddLinkName() { return "Submit your own patient review"; }
	public boolean getNameInTitle() { return false; }
	
	int rating;
	String firstName;
	String lastName;
	boolean namePermission;
	String email;
	String title;
	
	@Override
	public void addFields() {
		super.addFields();
		
		removeField("name");
		addField("title", "Reason for Visit:").setInIndex(true);
		addField("rating", "Rating:").setInIndex(true).setStars(5);
		addField("doctor", "Doctor:");
		addField("description", "Description:").setTextarea(true).setInIndex(true);
		addField("name", "Name:").setInIndex(true).setHeader(2).setApproved(namePermission);
		addField("namePermission", "I give my permission to use my first name and last initial on the website:").setApproved(false);
		addField("email", "Email:").setApproved(false);
	}
	
	@Override
	public String getName() {
		String result = "";
		
		if(!StringUtils.isEmpty(firstName))
			result += firstName;
		if(!StringUtils.isEmpty(firstName) && !StringUtils.isEmpty(lastName))
			result += " ";
		if(!StringUtils.isEmpty(lastName))
			result += lastName.substring(0, 1);
		
		return result;
	}
	
	public Review() {
		setOrder("name");
	}
	public int getRating() {
		return rating;
	}
	public void setRating(int rating) {
		this.rating = rating;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public boolean isNamePermission() {
		return namePermission;
	}
	public void setNamePermission(boolean namePermission) {
		this.namePermission = namePermission;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
}
